var Feedback = {
	currentId: null,
	listInit: function(){
		Feedback.feedbackClickJump(1);

	},
	feedbackClick: function(pageno){
		var cont = GetLS("cont");
      	Feedback.feedbackClickJump(pageno);
      	$("#pager").pager({pagenumber: pageno, pagecount: cont, buttonClickCallback: Feedback.feedbackClick });
	},
	feedbackClickJump: function(pageno){
		var count = Res.sinCount;
      	var start = (pageno-1)*count;
		$ajax({
			url:"/feedback/list",
			data:{
				start: start,
				count: count
			},
			success: function(res){
				var cont = parseInt(res.result.count/Res.sinCount);
                if((res.result.count)%Res.sinCount!=0){
                     cont++;
                }
                SetLS("cont",cont);
                if($("#pager").children().length == 0)
                    $("#pager").pager({ pagenumber: pageno, pagecount: cont, buttonClickCallback: Feedback.feedbackClick });
			
				var html =  '<thead><tr>'+
                            '<th class="span5">问题</th>'+  
                            '<th class="span2">提问人</th>'+
                            '<th class="span2">日期</th>'+
                            '<th class="span3">反馈内容</th>'+
                            '<th class="span2">操作</th>'+
	                    	'</tr></thead><tbody>';
	            var items = res.result.results;
	            var length = items && items.length || 0;
	            for (var i=0; i<length; i++) {
	            	var btnHtml = '<button class="">回复</button> ';
	            	html += '<tr data-pos="'+ i +'" style:" style=" width: 300px;"">'+
	            				'<td>'+ items[i].question +'</td>'+ 
	            				'<td>'+ items[i].fromName +'</td>'+ 
	            				'<td>'+ (new Date(items[i].create)).pattern("yyyy-MM-dd") +'</td>'+ 
	            				'<td id="' + items[i]._id + '">'+ (items[i].answer?items[i].answer:"") +'</td>'+ 
	            				'<td>'+ 
								"<a data-id='" + items[i]._id + "' data-action='REJECT' class='btn btn-danger  btn-mini'>回复</i></a>" +'</td>'+

	            			'</tr>';

	            }
	            html += '</tbody>';
	            $("#listCtn").html(html);
	                $(".btn-danger").click(function(){
	                	Feedback.currentId = $(this).data("id");
                        ShowCover("提示信息","请输入回复","","Feedback.reply()");
                    });
			}
		});	       
	},
	reply: function(){
      	var answer = $("#full-name").val();
          $ajax({
               url: "/feedback/upsert",
               data: {
               		_id: Feedback.currentId,
               		answer: answer
               },
               success: function(res){
                    $("#"+Feedback.currentId).text(answer);
                    $("#cover").html("");
               }
          });
     },
}